<?php

/**
 * Talis Aspire Lists block
 *
 * @package     block
 * @subpackage  aspirelists
 * @copyright   2011 Lancaster University Network Services Limited
 * @license     http://www.gnu.org/licenses/lgpl.html GNU LGPL
 * @author      Andrew Nicols <andrew.nicols@luns.net.uk>
 */

defined('MOODLE_INTERNAL') || die;

/**
 * The renderer class for the Talis Aspire aspirelists block
 */
class block_aspirelists_renderer extends plugin_renderer_base {

    /**
     * Produce the HTML output to display within the block
     *
     * @param array $lists The list of elements to display. See {@see
     *              display_list_item} for information on the format of the
     *              array elements
     * @return string The HTML output
     */
    public function block_display($lists) {
        $output = '';

        $output .= html_writer::start_tag('ul');
        foreach ($lists as $list) {
            $output .= $this->display_list_item($list);
        }
        $output .= html_writer::end_tag('ul');

        return $output;
    }

    /**
     * Compose the list element for the item specified
     *
     * @param stdClass $list Containing the list URL, Name, the time that
     *              the item was last updated, and the number of items
     * @param string The HTML output for this list element
     */
    public function display_list_item($list) {
        $listproperties = array(
            'target' => 'new',
            'title' => get_string('listtitletext', 'block_aspirelists', $list),
        );
        $list->link = html_writer::link(new moodle_url($list->url), $list->name, $listproperties);
        if ($list->count === 1) {
            $text = get_string('itemdata', 'block_aspirelists', $list);
        } else {
            $text = get_string('itemsdata', 'block_aspirelists', $list);
        }

        $item = html_writer::tag('li', $text);
        return $item;
    }
}
